package ar.com.e2solver.view;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;

import ar.com.e2solver.conf.E2SolverConfiguration;

public class ConfigurationView extends Panel {
	
	private static final long serialVersionUID = 1L;
	private E2SolverConfiguration configuration;
	
	private TextField populationField;
	private TextField iterationsField;

	public ConfigurationView(E2SolverConfiguration solverConfiguration) {
		this.configuration = solverConfiguration;
		initialize();
	}

	private void initialize() {
		BorderLayout bl = new BorderLayout();
		this.setLayout(bl);
		
		Panel fieldsPanel = new Panel();
		GridLayout gl = new GridLayout(2,2);
		fieldsPanel.setLayout(gl);
		
		Label populationLabel = new Label("Poblacion: ");
		this.populationField = new TextField(this.getConfiguration().getPopulationNumber().toString(), 3);
		Label iterationsLabel = new Label("Iteraciones: ");
		this.iterationsField = new TextField(this.getConfiguration().getIterations().toString(),10);
		
		fieldsPanel.add(populationLabel);
		fieldsPanel.add(this.populationField);
		fieldsPanel.add(iterationsLabel);
		fieldsPanel.add(this.iterationsField);
		
		this.add(fieldsPanel, BorderLayout.NORTH);
	}
	
	public void updateConfiguration(){
		int population = Integer.parseInt(this.populationField.getText());
		int iterations = Integer.parseInt(this.iterationsField.getText());
		this.getConfiguration().setIterations(iterations);
		this.getConfiguration().setPopulationNumber(population);
	}

	public E2SolverConfiguration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(E2SolverConfiguration configuration) {
		this.configuration = configuration;
	}

}
